<template>
	<view style="height: 100%">
		<!-- <top title="首页" color="#fff" bgc="transparent" :show="2" position="absolute"></top> -->
		<!-- <image src="https://cdn.xtwaixie.com/uploads/20240705/17201808706687e08666656.png" class="home-bg"></image> -->
		<!-- 轮播 -->

		<swiper class="home-swiper" :style="'height: ' + windowWidth * 0.67 +  'rpx;position:relative;'"
			:indicator-dots="true" :circular="true" indicator-color="rgba(255,255,255,.3)" indicator-active-color="#fff"
			:autoplay="true" interval="5000">
			<swiper-item class="home-swiper-item" v-for="(item, index) in home_list" :key="index">
				<image mode="aspectFill" class="swiper-img" referrerPolicy='no-referrer' :src="item.thumb"
					@tap="onSwiper" :data-item="item" />
			</swiper-item>

		</swiper>
		<view class="pr">
			<add-tips />
			<!-- 		<view class="add-box" v-if="add_show == 1">
				<view class="add-sjx"></view>
				<view class="add-cont df ac sb">
					<image class="img12" src="https://wx.xtwaixie.com/img/close3.png" @tap="onAddClose"></image>
					<p class="f14 cf ml12">添加到我的小程序 打开更方便</p> -->
			<!-- <button class="add-but">添加</button> -->
			<!-- 	</view>
			</view> -->
		</view>

		<view class="banner_list_box">
			<view class="banner_list">
				<view class="banner_list_item" v-for="(item,index) in banner_list" :key="index"
					@click="goOtherPage(item.url)">
					<view class="">
						<image :src="getImgSrc(item.img)" mode="widthFix"></image>
					</view>
					<view class="" style="font-size: 30rpx;font-weight: bold;margin: 5rpx 0rpx;">
						{{item.name}}
					</view>
					<view class="f11" style="color: gray;">
						{{item.content}}
					</view>
				</view>
			</view>
		</view>
		<view class="" style="height: 140rpx;"></view>
		<view class="" style="padding:0rpx 30rpx 30rpx 30rpx;box-sizing:border-box;">
			<view class="" style="margin: 25rpx 0;border-radius:16rpx;overflow: hidden;" v-if='content'>
				<van-notice-bar left-icon="volume-o" :text="content" color='#283043' background='#FFFFFF' />
			</view>
			<view class="" style="height: 50rpx;" v-else>

			</view>
			<!-- 工厂 -->
			<view>
				<view class="df ac sb">
					<view class="">
						<h2 class="f16 c28 f600">距您最近的优质工厂</h2>
					</view>
					<view class="moreList f12" @tap="goFactory">
						更多工厂
					</view>
				</view>
				<view v-if="isAuth_location" class="bgcf" style="min-height:300rpx;margin-top: 20rpx;">
					<view v-if="settled_list != 0">
						<FactoryInfo :list="settled_list" :isIndex="false" />
					</view>
					<view v-else style="padding:0rpx 30rpx; box-sizing: border-box; min-height:430rpx;">
						<view class="skeleton">
							<view class="row df ac sb">
								<view class="skeleton_left"></view>
								<view class="skeleton_right">
									<view class="skeleton_title"></view>
									<view class="skeleton_content1"></view>
									<view class="skeleton_content2"></view>
									<view class="skeleton_content3"></view>
								</view>
							</view>
							<view class="row">
								<view class="skeleton_products df ac sb">
									<view class="skeleton_products_item" v-for="(item,index) in 4" :key="index"></view>
								</view>
							</view>
						</view>
					</view>
				</view>
				<view class="mt10" v-else>
					<AuthorizeMap @emitAuth="emitAuth" />
				</view>
			</view>

			<!-- 最新需求 -->
			<view class="mt10" v-if="info.demand.length != 0">
				<view class="df ac sb">
					<view class="">
						<h2 class="f16 c28 f600">最新订单</h2>
					</view>
					<view class="moreList f13" @tap="go">
						更多订单
					</view>
					<!-- <navigator class="df ac" url="/pages/demand/demand" hover-class="none" open-type="navigate">
        <p class='f12 c9d mr5'>查看更多</p>
        <image class="more" src="../../img/more.png" />
			</navigator> -->

					<!--                   <view class="bgc10 br12 df ac sb pd510 fl ml10">
                        <p class="f12 cf">关注公众号，免费获取最新提醒</p>
                        <view class="gz-but1 ml10" @tap="goWeb">关注</view>
                    </view> -->
				</view>
				<ul class="mt10 db">
					<view class="bgcf mb10"
						style="padding:0rpx 30rpx 30rpx 20rpx;box-sizing:boder-box;border-radius: 15rpx;"
						v-for="(item, index) in info.demand" :key="index">
						<view @tap="demandDetails(item.id)" class=" xpg df pd150" style="align-items: center;"
							:style="{padding:item.is_quotation !== 0 ? '11.33rpx 0' : '30rpx 0 12rpx'}">
							<view class="f1 mr10" :class="{gray:item.is_end == 1 || item.is_deal == 1}">
								<view class="">
									<!-- <p class='tag mr8' wx:if='{{item.machining_name}}'>{{item.machining_name}}</p> -->
									<P :class="'f14  f600 ' + (item.is_end == 1 || item.is_deal == 1 ? 'c3c' : 'c28')">
										{{ item.spare_parts_name }}
									</P>
								</view>
								<view class="df ac mt8">
									<image class="img12" src="https://wx.xtwaixie.com/img/dz2.png" />
									<span
										:class="'f12 c6b ml4 ' + (item.is_end == 1 || item.is_deal == 1 ? 'c3c' : 'c28')">{{ item.province }}
										{{ item.city }}</span>
									<p class="line"></p>
									<!-- <span class='c10 f500 f12 {{item.is_end==1?"c28":"c28"}}'>共{{item.count}}件</span> -->
									<view
										:class="'c10 f500 f12 ' + (item.is_end == 1 || item.is_deal == 1 ? 'c3c' : 'c28')">
										<!-- {{ item.parts_count >= 2 ? '共' + item.parts_count + '款' : item.parts_piece ? (item.count == 0 ? '' : '共' + item.count) + item.parts_piece : '' }} -->
										<!-- {{  item.parts_piece ? (item.count == 0 ? '' : '共' + item.count) + item.parts_piece : '' }} -->
										{{item.count == 0?'':'共'+item.count+item.parts_piece}}
									</view>

									<view class="df ac">
										<p class="tag tag1 ml4" v-if="grade > 0 && item.view_type > 0">
											<text v-if='item.view_type == 1'>免费</text>
											<text v-if='item.view_type == 2'>VIP</text>
											<text v-if='item.view_type == 3'>至尊</text>
										</p>
										<!-- <p class="tag tag1 ml4" v-if="true">
											{{ item.view_type == 1 ? '免费' : 'VIP' }}
										</p> -->
										<!-- {{item}} -->
									</view>
									<!-- <p class="tag tag1 ml4">{{ item.view_integral }}积分</p> -->
								</view>
								<view class="df ac mt10">
									<p :class="'f12 c9d ' + (item.is_end == 1 || item.is_deal == 1 ? 'c3c' : 'c28')">
										{{ item.company }}
									</p>
									<p
										:class="'f12 c9d ml10 ' + (item.is_end == 1 || item.is_deal == 1 ? 'c3c' : 'c28')">
										报价截止：{{ item.end_at }}</p>
								</view>
							</view>
							<view class="img72 pr" hover-class="none" :hover-stop-propagation="false"
								style="height: auto;">
								<!-- <view class="quotationNum" v-if="item.is_quotation !== 0"
									:class="{gray:item.is_end == 1 || item.is_deal == 1}"> 已报价:{{item.quotation_count}}
								</view> -->
								<image class="img72" style="" referrerPolicy='no-referrer'
									:src="getImgSrc(item.redrawing) ? getImgSrc(item.redrawing) : ''"
									style="vertical-align: bottom;"
									:class="{gray:item.is_end == 1 || item.is_deal == 1}" />
								<p class="bj" v-if="item.is_deal == 1"
									:class="{gray:item.is_end == 1 || item.is_deal == 1}">已完成
								</p>
								<p class="bj" v-else-if="item.is_end == 2">报价中</p>
								<p class="bj" v-else :class="{gray:item.is_end == 1 || item.is_deal == 1}">已完成</p>
								<image class="yjs" mode="widthFix"
									src="https://cdn.xtwaixie.com/uploads/20240415/1713167495661cdc8768cb9.png"
									style="left: -100%;width: 140rpx;top: 50%;transform: translateY(-50%);filter: none !important;"
									v-if="item.is_deal == 1 || item.is_end == 1"></image>
							</view>
						</view>
						<view class="df sb ac" style="align-items: flex-start;">
							<view :class="{gray:item.is_end == 1 || item.is_deal == 1}">
								<view class="df ac mb5 fw" v-if="item.custom_tag.length !== 0">
									<view class="f11 mr5 c10 mb5"
										style="padding:5rpx 6rpx;border:1px solid rgba(64,115,210,0.6);border-radius:8rpx;"
										v-for="(item2,index2) in item.custom_tag" :key="index2">
										{{item2}}
									</view>
								</view>
								<view class=" f12 df ac" v-if="item.remarks && item.remarks != ''">
									<view>"</view>
									<view class="quotation_text"
										:style="item.is_end == 1 || item.is_deal == 1 ? 'color:#8D8D8D;' : ''">
										{{ item.remarks }}
									</view>
									<view>"</view>
								</view>
							</view>
							<view class="">
								<view v-if="item.quotation_count >= 0 && item.quotation_count <= 5">
									<view class="is_quotation greenStyle f12" v-if="item.is_quotation !== 0"
										:class="{gray:item.is_end == 1 || item.is_deal == 1}">
										已报价:{{item.quotation_count}}
									</view>
								</view>
								<view v-else-if="item.quotation_count >= 6 && item.quotation_count <= 10">
									<view class="is_quotation orangeStyle f12" v-if="item.is_quotation !== 0"
										:class="{gray:item.is_end == 1 || item.is_deal == 1}">
										已报价:{{item.quotation_count}}
									</view>
								</view>
								<view v-else>
									<view class="is_quotation redStyle f12" v-if="item.is_quotation !== 0"
										:class="{gray:item.is_end == 1 || item.is_deal == 1}">
										已报价:{{item.quotation_count}}
									</view>
								</view>
							</view>
						</view>
					</view>
					<view style="height: 150rpx;"></view>
				</ul>
			</view>
			<!-- 推荐商品 -->
			<!-- <view v-if="info.hotGoods.length != 0" :style="{'margin-top':info.demand.length != 0 ? '50rpx' : '0'}">
				<view class="df ac sb">
					<h2 class="db f18 f600 c28">推荐商品</h2>
					<view class="df ac search-home-box" @tap="goSearch">
						<image src="https://wx.xtwaixie.com/img/home-search.png" class="img12"></image>
						<P class="ml8 c28 f12">搜索商品名称</P>
					</view>

					<view class="df ac" @tap="goAbout">
						<image src="https://wx.xtwaixie.com/img/cz.png" class="img16"></image>
						<p class="f12 c6b ml4">如何搜索</p>
					</view>
				</view>
				<ul class="df ac fw mt15">
					<block v-for="(item, index) in info.hotGoods" :key="index">
						<navigator class="shop-list" :url="'/pages/order/shopDetail?id=' + item.id" hover-class="none"
							open-type="navigate">
							<image class="list-img" referrerPolicy='no-referrer' :src="item.thumb" />
							<view class="pd8">
								<p class="pd ovh2 f12 c28">{{ item.title }}</p>
								<view class="mt5 df ac sb">
									<h2 class="f14 db cff8">¥{{ item.price }}</h2>
								</view>
							</view>
						</navigator>
					</block>
				</ul>
			</view> -->
		</view>

		<button class="kfs-box" open-type="contact">
			<image class="kfs" src="https://wx.xtwaixie.com/img/kf3.png" @tap="onKfShow"></image>
		</button>
		<!-- <view class="kfs-box" >
	<image class="kfs" src="../../img/kf3.png" bindtap='onKfShow'></image>
	<view class="kfs-cont {{kf_show?'kf-out':'kf-in'}}">
		<view class="df ac h28 ml4">
			<button class="add-but" wx:if='{{kf_show}}' open-type="contact">咨询</button>
			<p class="f12 cf ml8">采购询价 图纸问题 接单服务</p>
		</view>
	</view>
</view> -->

		<tabbar></tabbar>
		<van-popup :show="showPopup" z-index='10000' position='bottom' :close-on-click-overlay='true'
			@close='showPopup = false' custom-style='background:rgba(0,0,0,0);' :safe-area-inset-bottom="false">
			<view class="popupBox" @click='showPopup = false'>
				<image referrerPolicy='no-referrer' :src="getImgSrc(publish_inquiry)" mode="widthFix" class="popupImg"
					@click.stop="goAdd()" style="width: 80%;"></image>
				<view style="height: 120rpx;width: 100%;">

				</view>
			</view>
		</van-popup>
		<van-popup :show="showTips" custom-style='background:#00000000;'>
			<image src="https://cdn.xtwaixie.com/uploads/20240108/1704702779659bb33b1136b.png" mode="widthFix"
				style="width: 450rpx;padding-bottom: 800rpx;"></image>
		</van-popup>

		<!-- is_expire -->
	<!-- 	<van-popup :show="is_expire" z-index='99999' position='bottom' :close-on-click-overlay='true'
			custom-style="background:rgba(0,0,0,0)" @close="hideExpire" :safe-area-inset-bottom="false">
			<view class="vip_expire_box"
				:style="'background-image:url('+ getImgSrc('/uploads/20241008/17283602686704af4c1edc8.png') +');'">
				<image style="width: 120rpx;display: block;margin: 0 auto;"
					:src="getImgSrc('/uploads/20240705/17201802276687de0394e88.png')" mode="widthFix"></image>
				<view class="mt15 f16">
					{{ expire_info.company }}
				</view>
				<view class="mt40 f20 f500">
					您的会员<text class="f24 f600" style="color:#FF0000;">{{ expire_info.vip_end_date }}</text>天后到期
				</view> -->
				<!-- <view class="mt10 f20 f500">
					到期前续费最高立减<text class="f24 f600" style="color:#FF0000;">1800</text>元
				</view> -->
				<!-- <navigator class="gopay" url="/pages/recharge/recharge"></navigator>
			</view>
		</van-popup> -->
	</view>
</template>

<script>
	import addTips from '@/component/addTips';
	import tabbar from '@/component/tabbar/tabbar';
	import top from '@/component/top/top';
	import http from '../../utils/http';
	import AuthorizeMap from '@/component/authorize-map/authorize-map'
	import FactoryInfo from '@/component/factory'
	export default {
		components: {
			tabbar,
			top,
			addTips,
			AuthorizeMap,
			FactoryInfo
		},
		data() {
			return {
				my_longitude: 0,
				my_latitude: 0,
				is_expire: false,
				expire_info: {
					vip_end_date: null,
					company: ''
				},
				shuiyin: this.shuiyin,
				info: {
					demand: [],
					hotGoods: []
				},
				banner_list: [{
						img: '/uploads/20240918/172665424466eaa724d15ee.png',
						name: '发布询价',
						content: '快至5分钟报价',
						url: '/pages/demand/subDemand'
					},
					{
						img: '/uploads/20240918/172665411066eaa69e3229a.png',
						name: '接单大厅',
						content: '查看最新订单',
						url: '/pages/demand/demand'
					},
					{
						img: '/uploads/20240918/172665438966eaa7b5aa8be.png',
						name: '工厂地图',
						content: '看地图，找工厂',
						url: '/pages/shopping/shopping'
					}
				],
				home_list: [],
				add_show: true,
				kf_show: false,
				grade: 0,
				content: '',
				showPopup: false,
				publish_inquiry: '',
				number_receive: false,
				remark: {},
				showTips: false,
				windowWidth: 0,
				isAuth_location: true,
				settled_list: [],
				is_show_popup: false
			};
		},
		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad(options) {
			let add_show = uni.getStorageSync('add_show') || 1;

			this.setData({
				add_show: add_show
			});
			const that = this
			uni.getSystemInfo({
				success: res => {
					that.windowWidth = res.screenHeight
				}
			})
			this.getUserInfo()

			const token = uni.getStorageSync('token')
			const code = uni.getStorageSync('is_login')
			if (token && code == 200) {
				that.getUserInfo()
			}

			// http.request('Weixin/message',{
			// 	path:'pages/recharge/recharge'
			// }).then(res=>{
			// 	console.log(res)
			// })

		},
		/**
		 * 生命周期函数--监听页面初次渲染完成
		 */
		onReady() {},
		/**
		 * 生命周期函数--监听页面显示
		 */
		onShow(options) {

			this.checkAuth()
			this.getBase();

			this.getHome();
			// if (uni.getStorageSync('token')) {
			// 	this.wxAuthLogin();
			// }
			// this.wxAuthLogin();
			// this.getContent()
		},
		/**
		 * 生命周期函数--监听页面隐藏
		 */
		onHide() {},
		/**
		 * 生命周期函数--监听页面卸载
		 */
		onUnload() {},
		/**
		 * 页面相关事件处理函数--监听用户下拉动作
		 */
		onPullDownRefresh() {},
		/**
		 * 页面上拉触底事件的处理函数
		 */
		onReachBottom() {
			uni.redirectTo({
				url: '/pages/demand/demand'
			})
		},
		/**
		 * 用户点击右上角分享
		 */
		onShareAppMessage() {},
		methods: {
			emitAuth(value) {
				this.isAuth_location = value
				if (this.isAuth_location) {
					this.checkAuth()
				}
			},
			checkAuth() {
				const that = this
				uni.getSetting({
					success(res) {
						that.isAuth_location = res.authSetting['scope.userLocation']
						const latitude = uni.getStorageSync('latitude')
						const longitude = uni.getStorageSync('longitude')
						const requestSettledList = (lat, lng, addressComponent) => {
							http.request('user_settled/list', {
								page: 1,
								pageSize: 1,
								longitude: lng,
								latitude: lat,
								my_longitude: lng,
								my_latitude: lat,
								keyword: '',
								distance: 0,
								machining: 0,
								service_industry: 0,
								province: '',
								city: "",
								type: 0
							}).then(ress => {
								that.settled_list = ress.data.data
								that.settled_list.forEach(item => {
									item.machining = item.machining.join('、')
									item.service_industry = item.service_industry.join('、')
									item.machining_products.forEach(el => {
										if (el.url.startsWith('[')) {
											try {
												el.url = JSON.parse(el.url);
											} catch (e) {
												el.url = null;
											}
										}
									});

								})
							}).catch(err => {
								uni.showToast({
									title: err.message,
									icon: 'none'
								})
							});
						}

						// 如果已授权，且有坐标信息  
						if (that.isAuth_location && latitude && longitude && uni.getStorageSync(
								'address_component')) {
							const address_component = JSON.parse(uni.getStorageSync('address_component'));
							requestSettledList(latitude, longitude, address_component);
							return; // 提早返回  
						}

						// 获取用户位置  
						uni.getLocation({
							isHighAccuracy: true,
							type: 'gcj02',
							success(rest) {
								const {
									latitude,
									longitude
								} = rest;
								that.my_longitude = longitude;
								that.my_latitude = latitude;
								uni.setStorageSync('latitude', latitude);
								uni.setStorageSync('longitude', longitude);

								// 如果地址组件已存在  
								if (uni.getStorageSync('address_component')) {
									const address_component = JSON.parse(uni.getStorageSync(
										'address_component'));
									requestSettledList(latitude, longitude, address_component);
								} else {
									// 如果不存在，则请求地址组件  
									uni.request({
										url: "https://apis.map.qq.com/ws/geocoder/v1/",
										data: {
											key: "XUDBZ-3OVAL-KWEPB-MXU6W-KW4XK-6WBHF",
											location: `${latitude},${longitude}`
										},
										success(result) {
											const data = result.data.result.address_component;
											uni.setStorageSync('address_component', JSON.stringify(
												data));
											requestSettledList(latitude, longitude, data);
										},
										fail(err) {
											console.error('Error fetching address component:',
												err);
										}
									});
								}
							},
							fail(err) {
								that.isAuth_location = false
								console.error('Failed to get location:', err);
							}
						});
					}
				});
			},
			checkExpire() {
				const currentDate = new Date().toLocaleDateString();
				const expireFlag = uni.getStorageSync('expireFlag') || {
					currentDate: '',
					show_popup: true
				};

				if (expireFlag.currentDate !== currentDate) {
					expireFlag.currentDate = currentDate;
					expireFlag.show_popup = true;
					uni.setStorageSync('expireFlag', expireFlag);
				} else {
					expireFlag.show_popup = false;
				}
				this.is_expire = expireFlag.show_popup;
			},
			hideExpire() {
				this.is_expire = false
				const expire_flag = {
					currentDate: new Date().toLocaleDateString(),
					show_popup: false
				}
				uni.setStorageSync('expireFlag', expire_flag)

				this.checkShowPopup()
			},
			checkShowPopup() {
				let currentZero = uni.getStorageSync('currentZero');
				if (currentZero) {
					let nowDate = new Date().setHours(0, 0, 0, 0)
					if (nowDate > currentZero) {
						uni.setStorageSync('currentZero', new Date().getTime())
						this.showPopup = true
					}
				} else {
					uni.setStorageSync('currentZero', new Date().getTime())
					this.showPopup = true
				}
			},
			openSet() {
				uni.openSetting({
					success(res) {
						console.log(res)
					},
					fail(err) {
						console.log(err)
					}
				})
			},
			goOtherPage(url) {
				if (!url) return
				uni.navigateTo({
					url: url
				})
			},
			demandDetails(id) {
				let first = uni.getStorageSync("firstPopup")
				if (!first) {
					this.showTips = true
					uni.setStorageSync('firstPopup', true)
				}
				let popupTime = uni.getStorageSync('popupTime');
				if (popupTime) {
					let nowDate = new Date().setHours(0, 0, 0, 0)
					if (nowDate > popupTime) {
						let that = this
						uni.requestSubscribeMessage({
							tmplIds: ['Ps_TGNHTlkFPLHybskEltaWoAvSZ1GhsoXfiJBGwTjA'],
							success(res) {
								if (res.Ps_TGNHTlkFPLHybskEltaWoAvSZ1GhsoXfiJBGwTjA == 'accept') {
									http.request('demand/empower')
									uni.setStorageSync('popupTime', new Date().getTime())
								}
								that.showTips = false
								uni.navigateTo({
									url: '/pages/demand/demandDetails?id=' + id
								})
							},
							fail(err) {
								// if (res.Ps_TGNHTlkFPLHybskEltaWoAvSZ1GhsoXfiJBGwTjA == 'accept') {
								// 	http.request('demand/empower')
								// 	uni.setStorageSync('popupTime', new Date().getTime())
								// }
								that.showTips = false
								uni.navigateTo({
									url: '/pages/demand/demandDetails?id=' + id
								})
							}
						})
					} else {
						let that = this
						that.showTips = false
						uni.navigateTo({
							url: '/pages/demand/demandDetails?id=' + id
						})
					}
				} else {
					let that = this
					uni.requestSubscribeMessage({
						tmplIds: ['Ps_TGNHTlkFPLHybskEltaWoAvSZ1GhsoXfiJBGwTjA'],
						success(res) {
							if (res.Ps_TGNHTlkFPLHybskEltaWoAvSZ1GhsoXfiJBGwTjA == 'accept') {
								http.request('demand/empower')
								uni.setStorageSync('popupTime', new Date().getTime())
							}
							that.showTips = false
							uni.navigateTo({
								url: '/pages/demand/demandDetails?id=' + id
							})
						},
						fail(err) {
							// if (res.Ps_TGNHTlkFPLHybskEltaWoAvSZ1GhsoXfiJBGwTjA == 'accept') {
							// 	http.request('demand/empower')
							// 	uni.setStorageSync('popupTime', new Date().getTime())
							// }
							that.showTips = false
							uni.navigateTo({
								url: '/pages/demand/demandDetails?id=' + id
							})
						}
					})
				}
			},
			goAdd() {
				this.showPopup = false
				if (this.remark.publish_inquiry) {
					let that = this
					uni.switchTab({
						url: that.remark.publish_inquiry,
						fail: function(res) {
							uni.navigateTo({
								url: that.remark.publish_inquiry
							})
						}
					})
				} else {
					uni.navigateTo({
						url: '/pages/demand/subDemand',
						fail: function(res) {
							uni.switchTab({
								url: '/pages/demand/subDemand'
							})
						}
					})
				}
			},
			go() {
				uni.navigateTo({
					url: "/pages/demand/demand"
				})
			},
			goFactory() {
				uni.navigateTo({
					url: "/pages/shopping/shopping"
				})
			},
			getContent() {
				http.request('base/pageCount')
					.then((res) => {
						this.content = res.data.gg ? res.data.gg.replace(/<img/g, '<img class="rich-text-img"') : '';
						console.log(this.content);
					})
					.catch((res) => {
						uni.showToast({
							title: res.message,
							icon: 'none'
						});
					});
			},
			// 获取个人信息
			getUserInfo() {

				const token = uni.getStorageSync('token')
				const login_code = uni.getStorageSync('is_login')

				if (token && login_code == 200) {
					http.request('user/userInfo').then((res) => {
						this.setData({
							grade: res.data.userInfo.grade,
						});
						this.expire_info.vip_end_date = res.data.userInfo.vip_end_date
						this.number_receive = res.data.userInfo.number_receive
						if (this.expire_info.vip_end_date <= 30 && res.data.userInfo.grade == 2) {
							this.checkExpire()
							const expireFlag = uni.getStorageSync('expireFlag')
							if (expireFlag && !expireFlag.show_popup) {
								this.checkShowPopup()
							}
						} else {
							this.checkShowPopup()
						}
					}).catch((res) => {
						uni.showToast({
							title: res.message,
							icon: 'none'
						});
					});
					http.request('user/settledInfo').then((res) => {
						this.expire_info.company = res.data.info.company
					}).catch((res) => {
						uni.showToast({
							title: res.message,
							icon: 'none'
						});
					});
				}
				// console.log(this.grade)
			},
			onKfShow() {
				this.setData({
					kf_show: !this.kf_show
				});
			},

			onAddClose() {
				this.setData({
					add_show: 2
				});
				uni.setStorageSync('add_show', 2);
			},

			onSwiper(e) {
				// console.log(e)
				let item = e.currentTarget.dataset.item;
				console.log(item)
				if (item.url_type == 12) {
					uni.navigateTo({
						url: '/subPack/factoryDetails/factoryDetails?id=' + item.goods_id
					});
					return
				}
				if (item.url == '/pages/landing/landing') {
					uni.navigateTo({
						url: '/pages/landing/landing'
					});
					return
				}
				if (item.url_type === 6) {
					uni.navigateTo({
						url: '/pages/recharge/recharge'
					});
					// if (uni.getSystemInfoSync().platform === 'ios') {
					// 	uni.navigateTo({
					// 		url: '/pages/recharge/iosvip'
					// 	});
					// } else {
					// 	uni.navigateTo({
					// 		url: '/pages/recharge/recharge'
					// 	});
					// }
					return
				}
				switch (item.url_type) {
					case 1:
						uni.redirectTo({
							url: '/pages/demand/subDemand'
						});
						break;
					case 2:
						uni.navigateTo({
							url: '/pages/order/shopDetail?id=' + item.goods_id
						});
						break;
					case 3:
						uni.redirectTo({
							url: '/pages/shopping/shopping'
						});
						break;
					case 4:
						uni.navigateTo({
							url: '/pages/content/content?id=' + item.id
						});
						break;
					case 5:
						uni.navigateTo({
							url: '/pages/settled/setPage'
						});
						break;
					case 7:
						uni.navigateTo({
							url: '/subPack/out/out?url=' + item.url
						});
						break;
					case 8:
						uni.navigateTo({
							url: '/pages/demand/demand'
						});
						break;
					case 9:
						uni.navigateTo({
							url: '/pages/myQuotation/myQuotation'
						});
						break;
					case 10:
						uni.navigateTo({
							url: '/pages/myInquiry/myInquiry'
						});
						break;
					case 11:
						uni.redirectTo({
							url: '/pages/shopping/shopping'
						});
						break;
				}
			},

			getHome() {
				http.request('base/indexData')
					.then((res) => {
						this.setData({
							info: res.data
						});
						this.info.demand = res.data.demand.map(i => {
							if (i.custom_tag == "") {
								i.custom_tag = []
							} else {
								i.custom_tag = i.custom_tag.split(',');
							}
							if(!i?.parts_piece){
								i.parts_piece='件'
							}
							return i
						})
					})
					.catch((res) => {
						console.log(res);
					});
			},

			getBase() {
				http.request('base/configData')
					.then((res) => {
						this.publish_inquiry = res.data.publish_inquiry
						this.remark = res.data.remark
						this.setData({
							home_list: res.data.new_home_banner
						});
					})
					.catch((res) => {
						console.log(res);
					});
			},

			wxAuthLogin() {
				let that = this;
				uni.login({
					complete: (res) => {
						let data = {
							code: res.code
						};
						let h = {
							'content-type': 'application/x-www-form-urlencoded'
						};
						uni.request({
							url: http.appUrl + 'login/getLogin',
							data: data,
							method: 'POST',
							header: h,
							success: (res) => {
								const token = res.data.data.token.token
								const code = res.data.code
								uni.setStorageSync('token', token);
								uni.setStorageSync('is_login', code);

								if (token && code == 200) {
									that.getUserInfo()
								}
							},
							fail: (res) => {
								console.log(res);
							},
						});
					}
				});
			},

			// 去查看公众号
			goWeb() {
				uni.navigateTo({
					url: '/pages/webview/webview'
				});
			},

			goSearch() {
				uni.navigateTo({
					url: '/pages/shopping/search'
				});
			},

			goAbout() {
				uni.navigateTo({
					url: '/pages/about/about?type=10'
				});
			},

		}
	};
</script>
<style lang="scss">
	@import './home.css';

	.popupBox {
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.popupImg {
		width: 550rpx;
	}

	.popupOut {
		width: 50rpx;
		height: 50rpx;
		margin-top: 100rpx;
	}

	.skeleton {
		border-radius: 20rpx;
		background: #fff;
		width: 100%;
		height: 100%;
		padding: 20rpx;
		box-sizing: border-box;

		.skeleton_left {
			width: 30%;
			height: 260rpx;
			background: #EFEFEF;
			border-radius: 15rpx;
			animation: opacityBg 1s ease-in-out infinite;
		}

		.skeleton_right {
			width: 68%;
			animation: opacityBg 1s ease-in-out infinite;
		}

		.skeleton_title {
			width: 100%;
			height: 40rpx;
			background: #EFEFEF;
		}

		.skeleton_content1 {
			width: 60%;
			height: 35rpx;
			background: #EFEFEF;
			margin-top: 20rpx;
		}

		.skeleton_content2 {
			width: 70%;
			height: 35rpx;
			background: #EFEFEF;
			margin-top: 20rpx;
		}

		.skeleton_content3 {
			width: 100%;
			height: 80rpx;
			background: #EFEFEF;
			margin-top: 20rpx;
		}

		.skeleton_products_item {
			width: 150rpx;
			height: calc(150rpx * 0.66);
			background: #EFEFEF;
			animation: opacityBg 1s ease-in-out infinite;
			border-radius: 10rpx;
			margin-top: 20rpx;
		}
	}

	@keyframes opacityBg {
		0% {
			opacity: 1;
		}

		50% {
			opacity: 0.8;
		}

		100% {
			opacity: 1;
		}
	}
</style>